package wwt_helper

import "github.com/speps/go-hashids"

// CreateCode 创建邀请码
func CreateCode(userId int, codeType string) string {
	hd := hashids.NewData()
	hd.Salt = "Oct1a_" + codeType
	hd.MinLength = 6
	hd.Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
	h, _ := hashids.NewWithData(hd)

	e, _ := h.Encode([]int{userId})
	return e
}

// DecodeCode 解析邀请码
func DecodeCode(code string, codeType string) []int {
	hd := hashids.NewData()
	hd.Salt = "Oct1a_" + codeType
	hd.MinLength = 6
	hd.Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
	h, _ := hashids.NewWithData(hd)

	d, _ := h.DecodeWithError(code)
	return d
}
